﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DataControl;
using System.Text;
using System.Collections;
using System.Data;

namespace ATW.MT.BUS
{
    public class bus_T_ProductionArgs
    {
        DataAccess da = null;
        public bus_T_ProductionArgs()
        {
            da = new DataAccess();
        }
        #region 方法
        /// <summary>
        /// 查询产品材质
        /// </summary>
        /// <param name="productionid">材质id</param>
        /// <param name="type">材质类型（1阀座，2阀杆，3阀瓣，4阀体，5填料）</param>
        /// <returns></returns>
        public DataTable getProductionMaterial(string productionid, string type)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select PM.[desc],
                                       M.Material_code code_d,
                                       isnull(M.Material_code_z ,'无') code_z,
                                       PMa.ProductionID,M.MID,PMa.RowId,PMa.type from T_Production_Material PMa
                                left join C_Material M on M.MID=PMa.MID
                                left join T_Production_MultiLan PM on PMa.ProductionID=PM.ProductionID 
                                    where [type]='{0}' and pma.ProductionID='{1}'", type, productionid);
            return da.ExecuteDataTable(sql.ToString());
        }

        /// <summary>
        /// 查询产品材质
        /// </summary>
        /// <param name="productionid">材质id</param>
        /// <param name="type">材质类型（1阀座，2阀杆，3阀瓣，4阀体，5填料）</param>
        /// <returns></returns>
        public DataTable getProductionMaterialNoLan(string productionid, string type)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select PMa.ProductionID,PMa.MID,PMa.RowId,PMa.type from T_Production_Material PMa
                           
                                    where [type]='{0}' and pma.ProductionID='{1}'", type, productionid);
            return da.ExecuteDataTable(sql.ToString());
        }
        /// <summary>
        /// 新增产品材质
        /// </summary>
        /// <param name="productionid">产品ID</param>
        /// <param name="materialID">材质ID</param>
        /// <param name="type">材质类型（1阀座，2阀杆，3阀瓣，4阀体，5填料）</param>
        /// <returns></returns>
        public string addProductionMaterial(string productionid, string materialID,string rowid, string type)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"insert into T_Production_Material(type,ProductionID,MID,rowid)values('{0}','{1}','{2}',{3})", type, productionid, materialID,rowid);
            return sql.ToString();
        }
        /// <summary>
        /// 移除产品材质
        /// </summary>
        /// <param name="productionid"></param>
        /// <param name="type">材质类型（1阀座，2阀杆，3阀瓣，4阀体，5填料）</param>
        /// <returns></returns>
        public string removeProductionMaterial(string productionid, string type)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"delete from T_Production_Material where type='{0}' and ProductionID='{1}'", type, productionid);
            return sql.ToString();
        }
        /// <summary>
        /// 获取材质
        /// </summary>
        /// <param name="productionid"></param>
        /// <returns></returns>
        public DataTable getProductionSize(string productionid)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select PM.[Desc],c.Size_Code_C,c.Size_Code_S,c.SID from T_Production_Size PS
                                left join C_Size c on c.[SID]=PS.[SID] 
                                left join T_Production P on PS.ProductionID=P.ProductionID
                                left join T_Production_MultiLan PM on P.ProductionID=PM.ProductionID and PM.LanId='zh'
                                where PS.ProductionID='{0}'", productionid);
            return da.ExecuteDataTable(sql.ToString());
        }
        /// <summary>
        /// 新增产品尺寸
        /// </summary>
        /// <param name="productionid"></param>
        /// <param name="sizeid"></param>
        /// <returns></returns>
        public string addProductionSize(string productionid, string sizeid)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"insert into T_Production_Size (ProductionID,SID)values('{0}','{1}')", productionid, sizeid);
            return sql.ToString();
        }
        /// <summary>
        /// 移除产品尺寸
        /// </summary>
        /// <param name="productionID"></param>
        /// <returns></returns>
        public string removeProductionSize(string productionID)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"delete from T_Production_Size where ProductionID='{0}'", productionID);
            return sql.ToString();
        }
        /// <summary>
        /// 获取产品压力等级
        /// </summary>
        /// <param name="productionID"></param>
        /// <returns></returns>
        public DataTable getProductionPressure(string productionID)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select * from T_Production_Pressure where productionid='{0}'", productionID);
            return da.ExecuteDataTable(sql.ToString());
        }
        /// <summary>
        /// 新增产品压力等级
        /// </summary>
        /// <param name="productionID"></param>
        /// <param name="pressureID"></param>
        /// <returns></returns>
        public string addProductionPressure(string productionID, string pressureID)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"insert into T_Production_Pressure (ProductionID,PressureID) values('{0}','{1}')", productionID, pressureID);
            return sql.ToString();
        }
        /// <summary>
        /// 移除产品压力等级
        /// </summary>
        /// <param name="productionID"></param>
        /// <returns></returns>
        public string removeProductionPressure(string productionID)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"delete from T_Production_Pressure where ProductionID='{0}'", productionID);
            return sql.ToString();
        }
        /// <summary>
        /// 获取产品设计标准
        /// </summary>
        /// <param name="productionID"></param>
        /// <returns></returns>
        public DataTable getProductionDesign(string productionID)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select * from T_Production_Design where ProductionID='{0}'", productionID);
            return da.ExecuteDataTable(sql.ToString());
        }
        /// <summary>
        /// 新增产品设计
        /// </summary>
        /// <param name="productionID"></param>
        /// <param name="designID"></param>
        /// <returns></returns>
        public string addProductionDesign(string productionID, string designID)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"insert into T_Production_Design (ProductionID,DesignLevelID) values('{0}','{1}')", productionID, designID);
            return sql.ToString();
        }
        /// <summary>
        /// 移除产品设计
        /// </summary>
        /// <param name="productionID"></param>
        /// <returns></returns>
        public string removeProductionDesign(string productionID)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"delete from T_Production_Design where ProductionID='{0}'", productionID);
            return sql.ToString();
        }
        /// <summary>
        /// 获取产品连接方式
        /// </summary>
        /// <param name="productionID"></param>
        /// <returns></returns>
        public DataTable getProductionConn(string productionID)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select * from T_Production_Conn where ProductionID='{0}'", productionID);
            return da.ExecuteDataTable(sql.ToString());
        }
        /// <summary>
        /// 新增产品连接方式
        /// </summary>
        /// <param name="productionID"></param>
        /// <param name="connID"></param>
        /// <returns></returns>
        public string addProductionConn(string productionID, string connID)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"insert into T_Production_Conn(ProductionID,ConnID) values('{0}','{1}')", productionID, connID);
            return sql.ToString();
        }
        /// <summary>
        /// 移除产品连接方式
        /// </summary>
        /// <param name="productionID"></param>
        /// <returns></returns>
        public string removeProductionConn(string productionID)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"delete from T_Production_Conn where ProductionID='{0}'", productionID);
            return sql.ToString();
        }
        /// <summary>
        /// 获取产品法兰标准
        /// </summary>
        /// <param name="ProductionID"></param>
        /// <returns></returns>
        public DataTable getProductionFran(string ProductionID)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select * from T_Production_Fran where ProductionID='{0}'", ProductionID);
            return da.ExecuteDataTable(sql.ToString());
        }
        /// <summary>
        /// 新增产品法兰标准
        /// </summary>
        /// <param name="ProductionID"></param>
        /// <param name="FranID"></param>
        /// <returns></returns>
        public string addProductionFran(string ProductionID, string FranID)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"insert into T_Production_Fran(ProductionID,FranLevelID)values('{0}','{1}')", ProductionID, FranID);
            return sql.ToString();
        }
        /// <summary>
        /// 移除法兰标准
        /// </summary>
        /// <param name="ProductionID"></param>
        /// <returns></returns>
        public string removeProductionFran(string ProductionID)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"delete from T_Production_Fran where ProductionID='{0}'", ProductionID);
            return sql.ToString();
        }
        /// <summary>
        /// 获取产品结构标准
        /// </summary>
        /// <param name="ProductionID"></param>
        /// <returns></returns>
        public DataTable getProductionStruct(string ProductionID)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select * from T_Production_Struct where ProductionID='{0}'", ProductionID);
            return da.ExecuteDataTable(sql.ToString());
        }
        /// <summary>
        /// 新增产品结构等级
        /// </summary>
        /// <param name="ProductionID"></param>
        /// <param name="StructID"></param>
        /// <returns></returns>
        public string addProductionStruct(string ProductionID, string StructID)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"insert into T_Production_Struct (ProductionID,StructLevelID)values('{0}','{1}')", ProductionID, StructID);
            return sql.ToString();
        }
        /// <summary>
        /// 移除产品结构等级
        /// </summary>
        /// <param name="ProductionID"></param>
        /// <returns></returns>
        public string removeProductionStruct(string ProductionID)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"delete from T_Production_Struct where ProductionID='{0}'", ProductionID);
            return sql.ToString();
        }
        /// <summary>
        /// 获取产品密封等级
        /// </summary>
        /// <param name="ProductionID"></param>
        /// <returns></returns>
        public DataTable getProductionSeal(string ProductionID)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select * from T_Production_Seal where ProductionID='{0}'", ProductionID);
            return da.ExecuteDataTable(sql.ToString());
        }
        public string addProductionSeal(string ProductionID, string SealID)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"insert into T_Production_Seal(ProductionID,SealLevelID)values('{0}','{1}')", ProductionID, SealID);
            return sql.ToString();
        }
        public string removeProductionSeal(string ProductionID)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"delete from T_Production_Seal where ProductionID='{0}'", ProductionID);
            return sql.ToString();
        }
        /// <summary>
        /// 获取产品描述
        /// </summary>
        /// <param name="ProductionID"></param>
        /// <returns></returns>
        public DataTable getProductionDesc(string ProductionID)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select pm.[Desc],pm.LanId,l.LanName from T_Production_MultiLan pm left join D_Language l 
                                on pm.LanId=l.LanId where ProductionID='{0}'", ProductionID);
            return da.ExecuteDataTable(sql.ToString());
        }
        /// <summary>
        /// 新增产品描述
        /// </summary>
        /// <param name="ProductionID"></param>
        /// <param name="LanID"></param>
        /// <param name="Desc"></param>
        /// <returns></returns>
        public int addProductionDesc(string ProductionID, string LanID, string Desc)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"insert into T_Production_MultiLan(ProductionID,LanID,[Desc])values('{0}','{1}',N'{2}')",
                ProductionID, LanID, Desc);
            return da.ExcuteNoQuery(sql.ToString());
        }
        /// <summary>
        /// 编辑产品描述
        /// </summary>
        /// <param name="ProductionID"></param>
        /// <param name="LanID"></param>
        /// <param name="Desc"></param>
        /// <returns></returns>
        public int editProductionDesc(string ProductionID, string LanID, string Desc)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"update T_Production_MultiLan set [Desc]=N'{0}' where ProductionID='{1}' and LanID='{2}'",
                Desc, ProductionID, LanID);
            return da.ExcuteNoQuery(sql.ToString());
        }
        /// <summary>
        /// 删除产品描述
        /// </summary>
        /// <param name="ProductionID"></param>
        /// <param name="LanID"></param>
        /// <returns></returns>
        public int delProductionDesc(string ProductionID, string LanID)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"delete from T_Production_MultiLan where ProductionID='{0}' and LanID='{1}'", ProductionID, LanID);
            return da.ExcuteNoQuery(sql.ToString());
        }
        /// <summary>
        /// 产品描述是否存在
        /// </summary>
        /// <param name="ProductionID"></param>
        /// <param name="LanID"></param>
        /// <returns></returns>
        public bool isProductionDescExist(string ProductionID, string LanID)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select * from T_Production_MultiLan where ProductionID='{0}' and LanID='{1}'", ProductionID, LanID);
            DataTable dt = da.ExecuteDataTable(sql.ToString());
            if (dt != null && dt.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
        /// <summary>
        /// 获取语言列表
        /// </summary>
        /// <returns></returns>
        public DataTable getLanList()
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select LanID,LanName from D_language");
            return da.ExecuteDataTable(sql.ToString());
        }
        /// <summary>
        /// 批量执行
        /// </summary>
        /// <param name="al"></param>
        /// <returns></returns>
        public bool Exal(ArrayList al)
        {
            return da.ExecuteArrayList(al);
        }
        #endregion
    }
}